{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <!-- 表单头部 -->
                <div class="card-header">
                    <div class="btn-group">
                        <a class="btn flat btn-sm btn-default BackButton">
                            <i class="fas fa-arrow-left"></i>
                            返回
                        </a>
                    </div>
                </div>
                <!-- 表单 -->
                <form id="dataForm" class="form-horizontal dataForm" action="" method="post" enctype="multipart/form-data">
                    <!-- 表单字段区域 -->
                    <div class="card-body">
                        <div class="form-group row rowSelect">
    <label for="order_id" class="col-sm-2 col-form-label">报量单</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="order_id" id="order_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择报量单">
            <option value=""></option>
            {foreach name='order_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.order_id==$item.id}selected{/if}>
        {$item.code}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#order_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
                        <div class="form-group row rowSelect">
    <label for="school_id" class="col-sm-2 col-form-label">学校</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="school_id" id="school_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择学校">
            <option value=""></option>
            {foreach name='school_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.school_id==$item.id}selected{/if}>
        {$item.name}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#school_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
<div class="form-group row rowDate">
    <label for="week" class="col-sm-2 col-form-label">日期</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <input id="week" readonly name="week" value="{$data.week|default=''}" placeholder="请选择日期" type="text" class="form-control filedDate">
    </div>
    <script>
        laydate.render({
            elem: '#week',
        });
    </script>
</div>
<div class="form-group row rowSelect">
    <label for="tag" class="col-sm-2 col-form-label">分类</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="tag" id="tag" class="form-control select2bs4 fieldSelect" data-placeholder="请选择分类">
            <option value=""></option>
                    {foreach tag_list as $key=>$value}
        <option value="{$key}" {if isset($data) && $data.tag==$key}selected{/if}>{$value}</option>
        {/foreach}



        </select>
    </div>

    <script>
        $('#tag').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>

<div class="form-group row">
                            <label class="col-sm-2 col-form-label ">菜谱清单</label>
                            <div class="col-sm-10 col-md-10">
                                <table id="settingSetting" class="table table-hover table-bordered datatable"
                                       width="100%">
                                    <thead>
                                    <tr class="input-type">
                                        <th>餐时</th>
                                        <th>套餐</th>
                                        <th>用餐人数</th>
                                        
                                        
                                        
                                    </tr>
                                    </thead>
                                    <tbody id="dataBody1">
                                    {if isset($data)}
                                    {foreach name='data.detail' id='item'}
                                    <tr>
                                        <td>
                                            <input class="form-control " placeholder="餐时" value="{$item.time|default=''}"
                                                   maxlength="50" type="text"   name="config_time[]" readonly>

                                        </td>
                                        <td>
                                            
                                            <select name="config_meal[]" class="form-control">
                {foreach name='meal_list' id='meal_item'}
                    <option value="{$meal_item.id}" {if isset($item.meal_id) && $item.meal_id==$meal_item.id}selected{/if}>
                        {$meal_item.name}
                    </option>
                {/foreach}
            </select>
                                        </td>
                                        <td>
                                            <input class="form-control " placeholder="用餐人数" value="{$item.num|default=''}"
                                                   maxlength="50" type="number"   name="config_num[]">

                                        </td>
                                    </tr>
                                    {/foreach}
                                    {else}
                                    <tr>
                                        <td>
                                            <input class="form-control "  value="早餐"
                                                   type="text"   name="config_time[]">

                                        </td>
                                        <td>
                                            
                                            <select name="config_meal[]" class="form-control">
                {foreach name='meal_list' id='meal_item'}
                    <option value="{$meal_item.id}" >
                        {$meal_item.name}
                    </option>
                {/foreach}
            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input class="form-control "  value="午餐"
                                                   type="text"   name="config_time[]">

                                        </td>
                                        <td>
                                            
                                            <select name="config_meal[]" class="form-control">
                {foreach name='meal_list' id='meal_item'}
                    <option value="{$meal_item.id}" >
                        {$meal_item.name}
                    </option>
                {/foreach}
            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input class="form-control "  value="晚餐"
                                                   type="text"   name="config_time[]">

                                        </td>
                                        <td>
                                            
                                            <select name="config_meal[]" class="form-control">
                {foreach name='meal_list' id='meal_item'}
                    <option value="{$meal_item.id}" >
                        {$meal_item.name}
                    </option>
                {/foreach}
            </select>
                                        </td>
                                    </tr>
                                    {/if}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                   
                    <div class="form-group row">
                            <label class="col-sm-2 col-form-label ">采购清单</label>
                            <div class="col-sm-10 col-md-10">
                                <table id="settingSetting" class="table table-hover table-bordered datatable"
                                       width="100%">
                                    <thead>
                                    <tr class="input-type">
                                        <th>操作</th>
                                        <th>商品</th>
                                        <th>规格</th>
                                        <th>单位</th>
                                        <th>数量</th>
                                        
                                        
                                        
                                    </tr>
                                    </thead>
                                    <tbody id="dataBody">
                                    {if isset($data)}
                                    {foreach name='data.detail2' id='item'}
                                    <tr>
                                        <td>
                                            <!-- <a class="btn btn-xs btn-primary" onclick="addNew(this,1)">插入</a> -->
                                            <a class="btn btn-xs btn-success" onclick="addNew(this,2)">追加</a>
                                            <a class="btn btn-xs btn-danger" onclick="delThis(this,1)">删除</a>
                                        </td>

                                        

                                        
                                        <td>
                                            
                                            <select name="config_type[]" class="form-control">
                {foreach name='type_list' id='type_item'}
                    <option value="{$type_item.id}" {if isset($item.type_id) && $item.type_id==$type_item.id}selected{/if}>
                        {$type_item.name}
                    </option>
                {/foreach}
            </select>
                                        </td>
                                        <td>
                                            
                                            <select name="config_spec[]" class="form-control">
                {foreach name='spec_list' id='spec_item'}
                    <option value="{$spec_item.id}" {if isset($item.spec_id) && $item.spec_id==$spec_item.id}selected{/if}>
                        {$spec_item.name}
                    </option>
                {/foreach}
            </select>
                                        </td>
                                        <td>
                                            
                                            <select name="config_brand[]" class="form-control">
                {foreach name='brand_list' id='brand_item'}
                    <option value="{$brand_item.id}" {if isset($item.brand_id) && $item.brand_id==$brand_item.id}selected{/if}>
                        {$brand_item.name}
                    </option>
                {/foreach}
            </select>
                                        </td>
                                        <td>
                                            <input class="form-control " placeholder="数量" value="{$item.num|default='0'}"
                                                   maxlength="50" type="number"   name="config_num[]">

                                        </td>
                                        
                                        
                                        
                                        
                                        
                                        
                                    </tr>
                                    {/foreach}
                                    
                                    </tbody>
                                </table>
                            </div>
                        </div>

                    {/if}

                    </div>
                    <!-- 表单底部 -->
                    <div class="card-footer">
                        <div class="row">
                            <div class="col-sm-2">
                            </div>

                            <div class="col-sm-10 col-md-4 formInputDiv">

                                <div class="btn-group">
                                    <button type="submit" class="btn btn-sm btn-primary dataFormSubmit">
                                        保 存
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="reset" class="btn btn-sm btn-default dataFormReset">
                                        重 置
                                    </button>
                                </div>

                                {if !isset($data)}
                                <div class="btn-group float-right createContinueDiv">
                                    <input type="checkbox" class="form-check-input" value="1" id="_create" name="_create" title="继续添加数据">
                                    <label class="form-check-label" for="_create">继续添加</label>
                                </div>
                                {/if}
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
<table>
    <tbody id="data-template" style="display: none">
    <tr>
        <td>
            <!-- <a class="btn btn-xs btn-primary" onclick="addNew(this,1)">插入</a> -->
            <a class="btn btn-xs btn-success" onclick="addNew(this,2)">追加</a>
            <a class="btn btn-xs btn-danger" onclick="delThis(this,1)">删除</a>
        </td>
        
       
        <td>
                                            
                                            <select name="config_type[]" class="form-control">
                {foreach name='type_list' id='type_item'}
                    <option value="{$type_item.id}" >
                        {$type_item.name}
                    </option>
                {/foreach}
            </select>
                                        </td>
                                        <td>
                                            
                                            <select name="config_spec[]" class="form-control">
                {foreach name='spec_list' id='spec_item'}
                    <option value="{$spec_item.id}" >
                        {$spec_item.name}
                    </option>
                {/foreach}
            </select>
                                        </td>
                                        <td>
                                            
                                            <select name="config_brand[]" class="form-control">
                {foreach name='brand_list' id='brand_item'}
                    <option value="{$brand_item.id}" >
                        {$brand_item.name}
                    </option>
                {/foreach}
            </select>
                                        </td>
                                        <td>
                                            <input class="form-control " placeholder="数量" value="0"
                                                   maxlength="50" type="number"   name="config_num[]">

                                        </td>
        
    </tr>

    </tbody>
</table>
{if !isset($data.detail2)}
<script>
    $(function () {
        addNew(null, 1);
    });
</script>
{else/}
<script>
    //$('#dataBody select').select2();
</script>
{/if}
<script>
    /** 表单验证 **/
    $('#dataForm').validate({
        rules: {
                'school_id': {
                required: true,

    },
    'week': {
                required: true,

    },

        },
        messages: {
                'school_id': {
               required: "学校不能为空",

    },
    'week': {
               required: "日期不能为空",

    },

        }
    });
    function addNew(obj, type) {
        var template = $('#data-template').html();
        if (obj == null) {
            $("#dataBody").append(template);
        } else {
            if (type === 1) {
                $(obj).parent().parent().before(template);
            } else {
                $(obj).parent().parent().after(template);
            }
        }

        $('#dataBody select').select2();
    }

    function delThis(obj) {
        layer.confirm('您确认删除本行吗？', {title: '删除确认', closeBtn: 1, icon: 3}, function () {
            $(obj).parent().parent().remove();
            layer.closeAll();
        });
    }
</script>
{/block}